package cn.kwq.project_manger.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import cn.kwq.project_manger.common.R;
import cn.kwq.project_manger.common.RES;
import cn.kwq.project_manger.pojo.dto.FindTagDto;
import cn.kwq.project_manger.pojo.dto.PageDto;
import cn.kwq.project_manger.service.TagService;
import com.alibaba.fastjson2.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags ="标签服务")
@RestController
@RequestMapping("/tag/")
@SaIgnore
public class TagController {

    @Autowired
    TagService tagService;

    @ApiOperation("查询项目标签列表")
    @PostMapping("findTag")
    public RES FindProjectTag(@RequestBody FindTagDto dto) {
        PageDto pageDto = tagService.FindProjectTags(dto);
        return R.ok(pageDto);
    }


    @ApiOperation("查询队伍标签列表")
    @PostMapping("findTag4Team")
    public RES FindTeamTag(@RequestBody FindTagDto dto) {
        PageDto pageDto = tagService.FindTeamTags(dto);
        return R.ok(pageDto);
    }


    @ApiOperation("新增标签(暂时不用，后端自动新增)")
    @PostMapping("addTag")
    public RES AddTag(@ApiParam(name = "tagName", value = "新增的标签的名字", required = true)
                          @RequestBody JSONObject object ) {
        String tagName = (String)object.get("tagName");

        String msg = tagService.AddNewTag(tagName);
        if (msg.equals("标签已存在")){
            throw new RuntimeException(msg);
        }else {
            return R.ok(msg+"新增成功");
        }

    }

}
